/* 用户注册 */
const router = require("koa-router")();
import { ReadFile,WriteFile } from '../utils/ReadWriteFile'
// import { createId } from '../utils/createId'
/* 查询所有的普通用户*/
router.post("/api/resetinterstpoint", async ctx => {
      const { username, type,interestPoints } = ctx.request.body;
      /* 只有包含用户才添加 */
      let result = await ReadFile(type);
      const res = result.find(item => item.username == username);
       res.interestPoints = interestPoints
      console.log(res)
      if (res) {
            // ctx.response.status = 400;
            let res1 = result.filter(item => item.username != username);
            res1.push(res);
            WriteFile({
                  type,
                  result:res1
            })
            ctx.body = {
                  code: 200,
                  msg: "添加成功",
            }
      }  else {
                  ctx.body = {
                        code: 400,
                        msg: "请先登录"
                  }
            }
      

})
module.exports = router;